/*
 * Copyright (C) 2017 Jolla Ltd.
 * Contact: Slava Monich <slava.monich@jolla.com>
 *
 * You may use this file under the terms of BSD license as follows:
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *   3. Neither the name of Jolla Ltd nor the names of its contributors may
 *      be used to endorse or promote products derived from this software
 *      without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef DBUSACCESS_PARSER_PRIVATE_H
#define DBUSACCESS_PARSER_PRIVATE_H

#include "dbusaccess_parser.h"

/* Stuff shared by the parser and the code generated by Bison/Flex */

typedef struct yyguts_t DAScanner;
typedef struct yy_buffer_state DAScannerBuffer;

#ifdef DEBUG
#  define YYDEBUG 1
extern int da_parser_debug;
#endif

#define YY_LEX da_parser_lex
#define YY_DECL int YY_LEX(union YYSTYPE* yylval_param, \
    DAScanner* yyscanner, DAParser* parser)

union YYSTYPE;
YY_DECL;

/* Generated parser */

void
da_parser_error(
    DAParser* parser,
    DAScanner* scanner,
    const char* error);

/* Generated scanner */

DAScanner*
da_scanner_create(
    void);

void
da_scanner_delete(
    DAScanner* scanner);

DAScannerBuffer*
da_scanner_buffer_create(
    const char* str,
    DAScanner* scanner);

void
da_scanner_buffer_delete(
    DAScannerBuffer* buffer,
    DAScanner* scanner);

int
da_parser_parse(
    DAParser* parser,
    DAScanner* scanner);

/* These are for the scanner */

void
da_parser_start_string(
    DAParser* parser);

void
da_parser_append_char(
    DAParser* parser,
    char c);

const char*
da_parser_finish_string(
    DAParser* parser);

/* And these are for the generated parser */

GSList*
da_parser_new_link(
    DAParser* parser,
    void* data);

char*
da_parser_new_string(
    DAParser* parser,
    const char* str);

DAParserExpr*
da_parser_new_expr_identity(
    DAParser* parser,
    int uid,
    int gid);

DAParserExpr*
da_parser_new_expr_custom(
    DAParser* parser,
    const char* name,
    const char* param);

DAParserExpr*
da_parser_new_expr(
    DAParser* parser,
    DA_PARSER_EXPR type,
    DAParserExpr* left,
    DAParserExpr* right);

DAParserEntry*
da_parser_new_entry(
    DAParser* parser,
    DAParserExpr* expr,
    DA_ACCESS access);

void
da_parser_add_entries(
    DAParser* parser,
    GSList* entries);

#endif /* DBUSACCESS_PARSER_PRIVATE_H */

/*
 * Local Variables:
 * mode: C
 * c-basic-offset: 4
 * indent-tabs-mode: nil
 * End:
 */
